package com.sojoys.artifact.factory.bytebuff;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;

import com.sojoys.artifact.build.data.base.BasePojo;
import com.sojoys.artifact.constant.ByteBuffEnum;
@SuppressWarnings({ "unchecked", "rawtypes" })
public abstract class IByteBuff {
	protected abstract void _writeByte(byte v) ;

	protected abstract void _writeBytes(byte[] v) ;
	
	protected abstract byte _readByte();

	protected abstract byte[] _readBytes(int readLength) ;

	public abstract byte[] toByte() ;
	
	public abstract IByteBuff reset();
	
	public void writeByte(byte v) {
		switch (v) {
		case ByteBuffType.BYTE_0:
			_writeByte(ByteBuffType.BYTE_0);
			break;
		case ByteBuffType.BYTE_1:
			_writeByte(ByteBuffType.BYTE_1);
			break;
		case ByteBuffType.BYTE_2:
			_writeByte(ByteBuffType.BYTE_2);
			break;
		case ByteBuffType.BYTE_3:
			_writeByte(ByteBuffType.BYTE_3);
			break;
		case ByteBuffType.BYTE_4:
			_writeByte(ByteBuffType.BYTE_4);
			break;
		case ByteBuffType.BYTE_5:
			_writeByte(ByteBuffType.BYTE_5);
			break;
		case ByteBuffType.BYTE_6:
			_writeByte(ByteBuffType.BYTE_6);
			break;
		case ByteBuffType.BYTE_7:
			_writeByte(ByteBuffType.BYTE_7);
			break;
		case ByteBuffType.BYTE_8:
			_writeByte(ByteBuffType.BYTE_8);
			break;
		case ByteBuffType.BYTE_9:
			_writeByte(ByteBuffType.BYTE_9);
			break;
		case ByteBuffType.BYTE_10:
			_writeByte(ByteBuffType.BYTE_10);
			break;
		default:
			_writeByte(ByteBuffType.BYTE);
			_writeByte(v);
			break;
		}

	}

	public void writeShort(short v) {
		if (v >= ByteBuffType.BYTE_MIN_VALUE && v <= ByteBuffType.BYTE_MAX_VALUE) {
			writeByte((byte) v);
		} else {
			_writeByte(ByteBuffType.SHORT);
			_writeByte((byte) ((v >> 8) & 0xff));
			_writeByte((byte) ((v >> 0) & 0xff));
		}
	}

	public void writeInt(int v) {
		if (v >= ByteBuffType.SHORT_MIN_VALUE && v <= ByteBuffType.SHORT_MAX_VALUE) {
			writeShort((short) v);
		} else {
			_writeByte(ByteBuffType.INT);
			_writeByte((byte) ((v >> 24) & 0xff));
			_writeByte((byte) ((v >> 16) & 0xff));
			_writeByte((byte) ((v >> 8) & 0xff));
			_writeByte((byte) ((v >> 0) & 0xff));
		}
	}

	public void writeLong(long v) {
		if (v >= ByteBuffType.INT_MIN_VALUE && v <= ByteBuffType.INT_MAX_VALUE) {
			writeInt((int) v);
		} else {
			_writeByte(ByteBuffType.LONG);
			_writeByte((byte) ((v >> 56) & 0xff));
			_writeByte((byte) ((v >> 48) & 0xff));
			_writeByte((byte) ((v >> 40) & 0xff));
			_writeByte((byte) ((v >> 32) & 0xff));
			_writeByte((byte) ((v >> 24) & 0xff));
			_writeByte((byte) ((v >> 16) & 0xff));
			_writeByte((byte) ((v >> 8) & 0xff));
			_writeByte((byte) ((v >> 0) & 0xff));
		}
	}

	public void writeFloat(float v) {
		_writeByte(ByteBuffType.FLOAT);
		int _v = Float.floatToIntBits(v);
		_writeByte((byte) ((_v >> 24) & 0xff));
		_writeByte((byte) ((_v >> 16) & 0xff));
		_writeByte((byte) ((_v >> 8) & 0xff));
		_writeByte((byte) ((_v >> 0) & 0xff));
	}

	public void writeDouble(double v) {
		if (v >= ByteBuffType.FLOAT_MIN_VALUE && v <= ByteBuffType.FLOAT_MAX_VALUE) {
			writeFloat((float) v);
		} else {
			_writeByte(ByteBuffType.DOUBLE);
			long _v = Double.doubleToLongBits(v);
			_writeByte((byte) ((_v >> 56) & 0xff));
			_writeByte((byte) ((_v >> 48) & 0xff));
			_writeByte((byte) ((_v >> 40) & 0xff));
			_writeByte((byte) ((_v >> 32) & 0xff));
			_writeByte((byte) ((_v >> 24) & 0xff));
			_writeByte((byte) ((_v >> 16) & 0xff));
			_writeByte((byte) ((_v >> 8) & 0xff));
			_writeByte((byte) ((_v >> 0) & 0xff));
		}
	}

	public void writeBoolean(boolean v) {
		_writeByte(v ? ByteBuffType.BOOLEAN_TRUE : ByteBuffType.BOOLEAN_FALSE);
	}

	public void writeString(String v) {
		byte[] _byte = v.getBytes(ByteBuffType.UTF8);
		int l = _byte.length;
		int _l = (ByteBuffType.STRING_1 - 1) + l;
		switch (_l) {
		case ByteBuffType.STRING_1:
			_writeByte(ByteBuffType.STRING_1);
			_writeBytes(_byte);
			break;
		case ByteBuffType.STRING_2:
			_writeByte(ByteBuffType.STRING_2);
			_writeBytes(_byte);
			break;
		case ByteBuffType.STRING_3:
			_writeByte(ByteBuffType.STRING_3);
			_writeBytes(_byte);
			break;
		case ByteBuffType.STRING_4:
			_writeByte(ByteBuffType.STRING_4);
			_writeBytes(_byte);
			break;
		case ByteBuffType.STRING_5:
			_writeByte(ByteBuffType.STRING_5);
			_writeBytes(_byte);
			break;
		case ByteBuffType.STRING_6:
			_writeByte(ByteBuffType.STRING_6);
			_writeBytes(_byte);
			break;
		case ByteBuffType.STRING_7:
			_writeByte(ByteBuffType.STRING_7);
			_writeBytes(_byte);
			break;
		case ByteBuffType.STRING_8:
			_writeByte(ByteBuffType.STRING_8);
			_writeBytes(_byte);
			break;
		case ByteBuffType.STRING_9:
			_writeByte(ByteBuffType.STRING_9);
			_writeBytes(_byte);
			break;
		case ByteBuffType.STRING_10:
			_writeByte(ByteBuffType.STRING_10);
			_writeBytes(_byte);
			break;
		default:
			_writeByte(ByteBuffType.STRING);
			writeByteArray(_byte);
			break;
		}
	}

	public void writeDate(Date date) {
		long v = date.getTime();
		_writeByte(ByteBuffType.DATE);
		_writeByte((byte) ((v >> 56) & 0xff));
		_writeByte((byte) ((v >> 48) & 0xff));
		_writeByte((byte) ((v >> 40) & 0xff));
		_writeByte((byte) ((v >> 32) & 0xff));
		_writeByte((byte) ((v >> 24) & 0xff));
		_writeByte((byte) ((v >> 16) & 0xff));
		_writeByte((byte) ((v >> 8) & 0xff));
		_writeByte((byte) ((v >> 0) & 0xff));
	}

	public void writeByteArray(byte[] v) {
		int l = v.length;
		int _l = (ByteBuffType.BYTE_ARRAY_1 - 1) + l;
		switch (_l) {
		case ByteBuffType.BYTE_ARRAY_1:
			_writeByte(ByteBuffType.BYTE_ARRAY_1);
			break;
		case ByteBuffType.BYTE_ARRAY_2:
			_writeByte(ByteBuffType.BYTE_ARRAY_2);
			break;
		case ByteBuffType.BYTE_ARRAY_3:
			_writeByte(ByteBuffType.BYTE_ARRAY_3);
			break;
		case ByteBuffType.BYTE_ARRAY_4:
			_writeByte(ByteBuffType.BYTE_ARRAY_4);
			break;
		case ByteBuffType.BYTE_ARRAY_5:
			_writeByte(ByteBuffType.BYTE_ARRAY_5);
			break;
		case ByteBuffType.BYTE_ARRAY_6:
			_writeByte(ByteBuffType.BYTE_ARRAY_6);
			break;
		case ByteBuffType.BYTE_ARRAY_7:
			_writeByte(ByteBuffType.BYTE_ARRAY_7);
			break;
		case ByteBuffType.BYTE_ARRAY_8:
			_writeByte(ByteBuffType.BYTE_ARRAY_8);
			break;
		case ByteBuffType.BYTE_ARRAY_9:
			_writeByte(ByteBuffType.BYTE_ARRAY_9);
			break;
		case ByteBuffType.BYTE_ARRAY_10:
			_writeByte(ByteBuffType.BYTE_ARRAY_10);
			break;
		default:
			_writeByte(ByteBuffType.BYTE_ARRAY);
			writeInt(v.length);
			break;
		}
		_writeBytes(v);
	}

	public void writeShortArray(short[] v) {
		_writeByte(ByteBuffType.SHORT_ARRAY);
		writeInt(v.length);
		for (int i = 0; i < v.length; i++) {
			writeShort(v[i]);
		}
	}

	public void writeIntArray(int[] v) {
		_writeByte(ByteBuffType.INT_ARRAY);
		writeInt(v.length);
		for (int i = 0; i < v.length; i++) {
			writeInt(v[i]);
		}
	}

	public void writeLongArray(long[] v) {
		_writeByte(ByteBuffType.LONG_ARRAY);
		writeInt(v.length);
		for (int i = 0; i < v.length; i++) {
			writeLong(v[i]);
		}
	}

	public void writeFloatArray(float[] v) {
		_writeByte(ByteBuffType.FLOAT_ARRAY);
		writeInt(v.length);
		for (int i = 0; i < v.length; i++) {
			writeFloat(v[i]);
		}
	}

	public void writeDoubleArray(double[] v) {
		_writeByte(ByteBuffType.DOUBLE_ARRAY);
		writeInt(v.length);
		for (int i = 0; i < v.length; i++) {
			writeDouble(v[i]);
		}
	}

	public void writeBooleanArray(boolean[] v) {
		_writeByte(ByteBuffType.BOOLEAN_ARRAY);
		writeInt(v.length);
		for (int i = 0; i < v.length; i++) {
			writeBoolean(v[i]);
		}
	}

	public void writeStringArray(String[] v) {
		_writeByte(ByteBuffType.STRING_ARRAY);
		writeInt(v.length);
		for (int i = 0; i < v.length; i++) {
			writeString(v[i]);
		}
	}

	public void writeDateArray(Date[] v) {
		_writeByte(ByteBuffType.DATE_ARRAY);
		writeInt(v.length);
		for (int i = 0; i < v.length; i++) {
			writeDate(v[i]);
		}
	}

	public void writeMap(Map map) {
		_writeByte(ByteBuffType.MAP);
		writeInt(map.size());
		Set<Entry> entrys = map.entrySet();
		for (Map.Entry entry : entrys) {
			writeObject(entry.getKey());
			writeObject(entry.getValue());
		}
	}

	public void writeList(List<Object> list) {
		_writeByte(ByteBuffType.LIST);
		writeInt(list.size());
		for (Object object : list) {
			writeObject(object);
		}
	}
	
	public void writeArray(Object[] array) {
		_writeByte(ByteBuffType.ARRAY);
		writeInt(array.length);
		for (int i = 0; i < array.length; i++) {
			writeObject(array[i]);
		}
	}
	
	public void writeNull(Object obj) {
		_writeByte(ByteBuffType.NULL);
	}
	
	public void writeObjects(Object...obj) {
		for (Object object : obj) {
			writeObject(object);
		}
	}
	
	public void writeObject(Object obj) {
		if(obj == null){
			writeNull(obj);
		}else if (obj instanceof Byte) {
			writeByte((byte) obj);
		} else if (obj instanceof Short) {
			writeShort((short) obj);
		} else if (obj instanceof Integer) {
			writeInt((int) obj);
		} else if (obj instanceof Long) {
			writeLong((long) obj);
		} else if (obj instanceof Float) {
			writeFloat((float) obj);
		} else if (obj instanceof Double) {
			writeDouble((double) obj);
		} else if (obj instanceof Boolean) {
			writeBoolean((boolean) obj);
		} else if (obj instanceof String) {
			writeString((String) obj);
		} else if (obj instanceof Date) {
			writeDate((Date) obj);
		} else if (obj instanceof byte[]) {
			writeByteArray((byte[]) obj);
		} else if (obj instanceof short[]) {
			writeShortArray((short[]) obj);
		} else if (obj instanceof int[]) {
			writeIntArray((int[]) obj);
		} else if (obj instanceof long[]) {
			writeLongArray((long[]) obj);
		} else if (obj instanceof float[]) {
			writeFloatArray((float[]) obj);
		} else if (obj instanceof double[]) {
			writeDoubleArray((double[]) obj);
		} else if (obj instanceof boolean[]) {
			writeBooleanArray((boolean[]) obj);
		} else if (obj instanceof String[]) {
			writeStringArray((String[]) obj);
		} else if (obj instanceof Date[]) {
			writeDateArray((Date[]) obj);
		} else if(obj.getClass().isArray()){
			writeArray((Object[]) obj);
		} else if (obj instanceof Map) {
			writeMap((Map) obj);
		} else if (obj instanceof List) {
			writeList((List<Object>) obj);
		}else if (obj instanceof BasePojo) {
			BasePojo sk = (BasePojo) obj;
			_writeByte(ByteBuffType.SAND_KING);
			writeString(obj.getClass().getName());
			writeByteArray(sk.toBytes(ByteBuffEnum.CUSTOM));
//			sk.writeBytes(this);
		}
	}

	
	public byte readByte(Byte type) {
		if (type == null)
			type = _readByte();
		switch (type) {
		case ByteBuffType.BYTE_0:
		case ByteBuffType.BYTE_1:
		case ByteBuffType.BYTE_2:
		case ByteBuffType.BYTE_3:
		case ByteBuffType.BYTE_4:
		case ByteBuffType.BYTE_5:
		case ByteBuffType.BYTE_6:
		case ByteBuffType.BYTE_7:
		case ByteBuffType.BYTE_8:
		case ByteBuffType.BYTE_9:
		case ByteBuffType.BYTE_10:
			return type;
		case ByteBuffType.BYTE:
			return _readByte();
		default:
			return 0;
		}
	}

	public short readShort(Byte type) {
		if (type == null)
			type = _readByte();
		if (type == ByteBuffType.SHORT) {
			int _v;
			_v = ((_readByte() & 0xff) << 8);
			_v += ((_readByte() & 0xff) << 0);
			short v = (short) (_v);
			return v;
		} else {
			return readByte(type);
		}
	}

	public int readInt(Byte type) {
		if (type == null)
			type = _readByte();
		if (type == ByteBuffType.INT) {
			int _v;
			_v = ((_readByte() & 0xff) << 24);
			_v += ((_readByte() & 0xff) << 16);
			_v += ((_readByte() & 0xff) << 8);
			_v += ((_readByte() & 0xff) << 0);
			return _v;
		} else {
			return readShort(type);
		}
	}

	public long readLong(Byte type) {
		if (type == null)
			type = _readByte();
		if (type == ByteBuffType.LONG) {
			long high;
			high = ((_readByte() & 0xff) << 24);
			high += ((_readByte() & 0xff) << 16);
			high += ((_readByte() & 0xff) << 8);
			high += ((_readByte() & 0xff) << 0);
			long low;
			low = ((_readByte() & 0xff) << 24);
			low += ((_readByte() & 0xff) << 16);
			low += ((_readByte() & 0xff) << 8);
			low += ((_readByte() & 0xff) << 0);
			long v = (high << 32) + (0xffffffffL & low);
			return v;
		} else {
			return readInt(type);
		}
	}

	public float readFloat(Byte type) {
		if (type == null)
			type = _readByte();
		if (type == ByteBuffType.FLOAT) {
			int _v;
			_v = ((_readByte() & 0xff) << 24);
			_v += ((_readByte() & 0xff) << 16);
			_v += ((_readByte() & 0xff) << 8);
			_v += ((_readByte() & 0xff) << 0);
			return Float.intBitsToFloat(_v);
		}
		return 0.0f;
	}

	public double readDouble(Byte type) {
		if (type == null)
			type = _readByte();
		if (type == ByteBuffType.DOUBLE) {
			long high;
			high = ((_readByte() & 0xff) << 56);
			high += ((_readByte() & 0xff) << 48);
			high += ((_readByte() & 0xff) << 40);
			high += ((_readByte() & 0xff) << 32);
			long low;
			low = ((_readByte() & 0xff) << 24);
			low += ((_readByte() & 0xff) << 16);
			low += ((_readByte() & 0xff) << 8);
			low += ((_readByte() & 0xff) << 0);
			long _v = (high << 32) + (0xffffffffL & low);
			return Double.longBitsToDouble(_v);
		} else {
			return readFloat(type);
		}
	}

	public boolean readBoolean(Byte type) {
		if (type == null)
			type = _readByte();
		switch (type) {
		case ByteBuffType.BOOLEAN_TRUE:
			return true;
		case ByteBuffType.BOOLEAN_FALSE:
			return false;
		default:
			return false;
		}
	}

	public String readString(Byte type) {
		if (type == null)
			type = _readByte();
		switch (type) {
		case ByteBuffType.STRING_1:
		case ByteBuffType.STRING_2:
		case ByteBuffType.STRING_3:
		case ByteBuffType.STRING_4:
		case ByteBuffType.STRING_5:
		case ByteBuffType.STRING_6:
		case ByteBuffType.STRING_7:
		case ByteBuffType.STRING_8:
		case ByteBuffType.STRING_9:
		case ByteBuffType.STRING_10:
			int l = type + 1 - ByteBuffType.STRING_1;
			byte[] b = _readBytes(l);
			return new String(b, ByteBuffType.UTF8);
		default:
			return new String(readByteArray(null), ByteBuffType.UTF8);
		}
	}

	public Date readDate(Byte type) {
		if (type == null)
			type = _readByte();
		if (type == ByteBuffType.DATE) {
			return new Date(readLong(ByteBuffType.LONG));
		}
		return null;
	}

	public byte[] readByteArray(Byte type) {
		int l = 0;
		if (type == null)
			type = _readByte();
		switch (type) {
		case ByteBuffType.BYTE_ARRAY_1:
		case ByteBuffType.BYTE_ARRAY_2:
		case ByteBuffType.BYTE_ARRAY_3:
		case ByteBuffType.BYTE_ARRAY_4:
		case ByteBuffType.BYTE_ARRAY_5:
		case ByteBuffType.BYTE_ARRAY_6:
		case ByteBuffType.BYTE_ARRAY_7:
		case ByteBuffType.BYTE_ARRAY_8:
		case ByteBuffType.BYTE_ARRAY_9:
		case ByteBuffType.BYTE_ARRAY_10:
			l = type + 1 - ByteBuffType.BYTE_ARRAY_1;
			break;
		default:
			l = readInt(null);
			break;
		}
		byte[] b = _readBytes(l);
		return b;
	}

	public short[] readShortArray(Byte type) {
		if (type == null)
			type = _readByte();
		int l = readInt(null);
		short[] b = new short[l];
		for (int i = 0; i < b.length; i++) {
			b[i] = readShort(null);
		}
		return b;
	}

	public int[] readIntArray(Byte type) {
		if (type == null)
			type = _readByte();
		int l = readInt(null);
		int[] b = new int[l];
		for (int i = 0; i < b.length; i++) {
			b[i] = readInt(null);
		}
		return b;
	}

	public long[] readLongArray(Byte type) {
		if (type == null)
			type = _readByte();
		int l = readInt(null);
		long[] b = new long[l];
		for (int i = 0; i < b.length; i++) {
			b[i] = readLong(null);
		}
		return b;
	}

	public float[] readFloatArray(Byte type) {
		if (type == null)
			type = _readByte();
		int l = readInt(null);
		float[] b = new float[l];
		for (int i = 0; i < b.length; i++) {
			b[i] = readFloat(null);
		}
		return b;
	}

	public double[] readDoubleArray(Byte type) {
		if (type == null)
			type = _readByte();
		int l = readInt(null);
		double[] b = new double[l];
		for (int i = 0; i < b.length; i++) {
			b[i] = readDouble(null);
		}
		return b;
	}

	public boolean[] readBooleanArray(Byte type) {
		if (type == null)
			type = _readByte();
		int l = readInt(null);
		boolean[] b = new boolean[l];
		for (int i = 0; i < b.length; i++) {
			b[i] = _readByte() == ByteBuffType.BOOLEAN_TRUE;
		}
		return b;
	}

	public String[] readStringArray(Byte type) {
		if (type == null)
			type = _readByte();
		int l = readInt(null);
		String[] b = new String[l];
		for (int i = 0; i < b.length; i++) {
			b[i] = readString(null);
		}
		return b;
	}

	public Date[] readDateArray(Byte type) {
		if (type == null)
			type = _readByte();
		int l = readInt(null);
		Date[] b = new Date[l];
		for (int i = 0; i < b.length; i++) {
			b[i] = readDate(null);
		}
		return b;
	}

	public Map readMap(Byte type) {
		if (type == null)
			type = _readByte();
		int l = readInt(null);
		Map map = new HashMap(l);
		for (int i = 0; i < l; i++) {
			map.put(readObject(), readObject());
		}
		return map;
	}

	public List<Object> readList(Byte type) {
		if (type == null)
			type = _readByte();
		int l = readInt(null);
		List<Object> list = new ArrayList<Object>(l);
		for (int i = 0; i < l; i++) {
			list.add(readObject());
		}
		return list;
	}
	
	private Object[] readArray(Byte type) {
		if (type == null)
			type = _readByte();
		int l = readInt(null);
		Object[] array = new Object[l];
		for (int i = 0; i < l; i++) {
			array[i] = readObject();
		}
		return array;
	}
	
	public List<Object> readNull(Byte type) {
		if (type == null)
			type = _readByte();
		if (type == ByteBuffType.NULL) {
			return null;
		} else {
			return null;
		}
	}
	
	public Object readObject() {
		byte type = _readByte();
		switch (type) {
		case ByteBuffType.NULL:
			return readNull(type);
		case ByteBuffType.BYTE:
		case ByteBuffType.BYTE_0:
		case ByteBuffType.BYTE_1:
		case ByteBuffType.BYTE_2:
		case ByteBuffType.BYTE_3:
		case ByteBuffType.BYTE_4:
		case ByteBuffType.BYTE_5:
		case ByteBuffType.BYTE_6:
		case ByteBuffType.BYTE_7:
		case ByteBuffType.BYTE_8:
		case ByteBuffType.BYTE_9:
		case ByteBuffType.BYTE_10:
			return (int)readByte(type);	//此处因为代码使用中一般是int类型 如果还返回短整型如果是MAP则要非常明确的指定类型才能取出数据
		case ByteBuffType.SHORT:
			return (int)readShort(type);   //此处因为代码使用中一般是int类型 如果还返回短整型如果是MAP则要非常明确的指定类型才能取出数据  
		case ByteBuffType.INT:
			return readInt(type);
		case ByteBuffType.LONG:
			return readLong(type);
		case ByteBuffType.FLOAT:
			return readFloat(type);
		case ByteBuffType.DOUBLE:
			return readDouble(type);
		case ByteBuffType.STRING:
		case ByteBuffType.STRING_1:
		case ByteBuffType.STRING_2:
		case ByteBuffType.STRING_3:
		case ByteBuffType.STRING_4:
		case ByteBuffType.STRING_5:
		case ByteBuffType.STRING_6:
		case ByteBuffType.STRING_7:
		case ByteBuffType.STRING_8:
		case ByteBuffType.STRING_9:
		case ByteBuffType.STRING_10:
			return readString(type);
		case ByteBuffType.DATE:
			return readDate(type);
		case ByteBuffType.BYTE_ARRAY:
		case ByteBuffType.BYTE_ARRAY_1:
		case ByteBuffType.BYTE_ARRAY_2:
		case ByteBuffType.BYTE_ARRAY_3:
		case ByteBuffType.BYTE_ARRAY_4:
		case ByteBuffType.BYTE_ARRAY_5:
		case ByteBuffType.BYTE_ARRAY_6:
		case ByteBuffType.BYTE_ARRAY_7:
		case ByteBuffType.BYTE_ARRAY_8:
		case ByteBuffType.BYTE_ARRAY_9:
		case ByteBuffType.BYTE_ARRAY_10:
			return readByteArray(type);
		case ByteBuffType.SHORT_ARRAY:
			return readShortArray(type);
		case ByteBuffType.INT_ARRAY:
			return readIntArray(type);
		case ByteBuffType.LONG_ARRAY:
			return readLongArray(type);
		case ByteBuffType.FLOAT_ARRAY:
			return readFloatArray(type);
		case ByteBuffType.DOUBLE_ARRAY:
			return readDouble(type);
		case ByteBuffType.BOOLEAN_ARRAY:
			return readBooleanArray(type);
		case ByteBuffType.STRING_ARRAY:
			return readStringArray(type);
		case ByteBuffType.DATE_ARRAY:
			return readDateArray(type);
		case ByteBuffType.MAP:
			return readMap(type);
		case ByteBuffType.LIST:
			return readList(type);
		case ByteBuffType.ARRAY:
			return readArray(type);
		case ByteBuffType.BOOLEAN_TRUE:
			return true;
		case ByteBuffType.BOOLEAN_FALSE:
			return false;
		case ByteBuffType.SAND_KING:
			String className = readString(null);
			try {
				Class<? extends BasePojo> clz = (Class<? extends BasePojo>) Class.forName(className);
				BasePojo skPpojo = clz.newInstance();
				return skPpojo.createForBytes(readByteArray(type), ByteBuffEnum.CUSTOM);
			} catch (ClassNotFoundException | InstantiationException | IllegalAccessException e) {
				e.printStackTrace();
			}
		default:
			return 0;
		}
	}
}
